<template>
	<view class="quan">
		<view class="swiperbox">
			<image src="/static/images/lqzx.png" mode=""></image>
		</view>
		<view class="container">
			<quanlist ling :list="list" @citem="lingqu" @updataUnfold="updataUnfold"></quanlist>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
import API from '@/common/api';
export default {
	name: 'quan',
	data() {
		return {
			status:'',
			params: {
				scene: 1,
				order1: 'dtTime',
				order2: 'desc'
			},
			paging: {
				page: 1,
				pagenum: 5
			},
			list: []
		};
	},
	onLoad() {},
	onShow() {
		this.reset();
		this.getList();
	},
	onReachBottom() {
		if (this.status === 'nomore') return;
		this.getList();
	},
	methods: {
		updataUnfold(e) {
			let { a, i } = e;
			this.list[i].unfold = a;
		},
		lingqu(item) {
			this.$http.getJson('users_yhqLingqu', { id: item.id }).then((res) => {
				if (res.code == 1) {
					this.msg(res.message,()=>{
						this.reset();
						this.getList();
					});
				}else{
					this.msg(res.message)
				}
			});
		},
		reset(){
			this.paging.page = 1;
			this.list = []
		},
		getList() {
			API.getJson('users_yhqList', { ...this.paging, ...this.params }).then((res) => {
				const { code, data, message } = res;
				if (code === 1) {
					data.forEach((item) => {
						item.unfold = false;
					});
					if (data.length !== 0) this.list = this.list.concat(data);
					if (this.paging.pagenum === data.length) {
						this.paging.page += 1;
						this.status = 'loadmore';
					} else {
						this.status = 'nomore';
					}
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
.quan {
	.swiperbox {
		image {
			width: 100%;
			height: 264rpx;
		}
	}
	.container {
		padding: 24rpx 32rpx;
	}
}
</style>
